138

Beginner’s Guide to Code Algorithms

138

STEP 1

PeopleInStore is the name of the worksheet.

Sub PeopleInStore()

Dim FileItem As Object

Dim SourceFolder As Object

Folder =​ “C:�sers\deepa\Documents\webcam photo\Motion\temp” ‘ this is the

folder that has the motion detection pictures

FolderNameIndex =​ 0

PeopleCount =​ 0

Set fs =​ CreateObject(“Scripting.FileSystemObject”)

Set SourceFolder =​ fs.GetFolder(Folder)

Worksheets(“PeopleInStore”).Cells(1,1).Value =​ “Date”

Worksheets(“PeopleInStore”).Cells(NextAvailableRow, 1).Value =​ “Count”

For Each FileItem In SourceFolder.Files

    PeopleCount =​ PeopleCount +​ 1

    FileItem.Delete

Next

NextAvailableRow =​ Worksheets(“PeopleInStore”).Cells(Rows.Count,

1).End(xlUp).Row

Worksheets(“PeopleInStore”).Cells(NextAvailableRow, 1).Value =​ Format(Date,

“MM/​DD/​YYYY”)

Worksheets(“PeopleInStore”).Cells(NextAvailableRow, 2).Value =​ PeopleCount

End Sub

10.4  REMOTE PHOTO

The third objective was to take a remote photo shot using googledocs.

Here we use some assistance from the code we wrote in one of our previous chap­

ters—​Remote Control. Here we described how a googledocs document can be used

to advance a slide in a powerpoint deck forward or backward. This is another example

of collaborative design—​we could use this same code but change the action from

moving a slide to taking a picture.

The way to take a picture is to just start the Yawcam application. Because this has

a feature to take a snap every so many seconds, configurable from the Settings menu.

All we need to do is start and stop the Yawcam application using googledocs,

similar to how we advanced the slides in Chapter 4.

Here is the code to start the Yawcam application from a spreadsheet:

ShellExecute 0, “OPEN”, “C:\Program Files (x86)\Yawcam\yawcam.exe”, ““,

”C:\Program Files (x86)\Yawcam\”, 1

Here is the code to stop the Yawcam application:

Call Shell(“TaskKill /​Fi ”“WindowTitle eq ““Yaw*““”““, 0)

10.5  TIME BASED GREETING

That brings us to our last objective—​greeting based on time of day.

Imagine someone comes into your office or your apartment and as soon as the

person walks in, the computer greets them with “Good Morning” or “Good Evening”,

etc. depending on the time of day.